#include <iostream>
#include <string>
#include <fstream>
#include "bundle.h"


int main(int argc,char* argv[])
{
    std::cout<<"argv[1] 是原始文件路径名称"<<std::endl;
    std::cout<<"argv[2] 是压缩包名称"<<std::endl;
    if(argc < 3)
    {
        std::cout<<"usage: argv[0] argv[1] argv[2]"<<std::endl;
        return -1;
    }

    std::string infile = argv[1];
    std::string oufile = argv[2];

    std::ifstream ifs;               //文件流
    ifs.open(infile,std::ios::binary);  //以二进制的形式打开原始文件
    ifs.seekg(0,ifs.end);   //光标跳到文件末尾
    int sz = ifs.tellg();  //获取原始文件大小
    ifs.seekg(0,ifs.beg);
    std::string body;
    body.resize(sz);
    ifs.read(&body[0],sz); //获取原始文件数据
    
    std::string packed = bundle::pack(bundle::LZIP,body);  //以lzip的格式对文件压缩

    std::ofstream ofs;
    ofs.open(oufile,std::ios::binary); //打开压缩包文件
    ofs.write(&packed[0],packed.size());  //将压缩后的数据写入压缩文件

    ifs.close();
    ofs.close();

    return 0;
}